#!/bin/bash

OLD_CUR_VER=`cat ws_cur_ver`

if [ -n "$1" ]
then
	WS_CUR_VER=$1
else
	svn info svn://192.168.10.49/HY/MobilePortal/Trunk/Src --xml | grep 'revision=' -m 1 | grep -E '[0-9]+'  -o > ws_cur_ver
	WS_CUR_VER=`cat ws_cur_ver`

fi

echo "Dumping $WS_CUR_VER"

svn export -r $WS_CUR_VER   svn://192.168.10.49/HY/MobilePortal/Trunk/Src  mobileportal_$WS_CUR_VER -q

#backup old source
cp -r mobileportal.ts bak.mobileportal_$OLD_CUR_VER
rm -rf mobileportal.ts/
cp -r mobileportal_$WS_CUR_VER mobileportal.ts

#restore user data
cp -r bak.mobileportal_$OLD_CUR_VER/Sites/forum.mobileportal.com/www/uc_server/data mobileportal.ts/Sites/forum.mobileportal.com/www/uc_server/data
cp -r bak.mobileportal_$OLD_CUR_VER/Sites/forum.mobileportal.com/www/data mobileportal.ts/Sites/forum.mobileportal.com/www/data


#set the directory below writeable
chmod 777 mobileportal.ts/Modules/protected/admin/runtime -R
chmod 777 mobileportal.ts/Modules/protected/runtime -R
chmod 777 mobileportal.ts/Sites/admin.mobileportal.com/www/assets -R
chmod 777 mobileportal.ts/Sites/www.mobileportal.com/www/assets -R
chmod 777 mobileportal.ts/Sites/forum.mobileportal.com/www/data -R
chmod 777 mobileportal.ts/Sites/forum.mobileportal.com/www/uc_server/data -R
